// 关于长度为64的字符串是如何转换为长度为80的数组，当字符串中出现汉字的解决方案

// 汉字编码的值为v_han 21 216
// 之后分别判断 v_han 是否小于128 2048 55296
// 之后或许arr80中对应项元素的值,如果之前没有执行操作，那么默认为0，这里定义为v_80
// 遍历字字符串的下标索引index2
// var v1,v2,v3,v4,v5;
// var arr_4 = [24, 16, 8, 0];
// v1 = v_han >> 12; // 119
// v2 = v1 | 224; //21
// v3 = arr_4[index2 & 3];// 239
// v4 = v2 << v3;// 54
// v5 = v_80 | v4;
// // 之后把v5更新到数组对应位置中即可,定义为new_v_80
//
// v6 = v_han >> 6;// 54
// v7 = v6 & 63; //239
// v8 = v7 | 128;// 54
// index2 += 1
// v9 = arr_4[index2 & 3]
// v10 = v8 << v9;//21
// v11 = v10 | new_v_80;
// // 之后把v11更新到数组对应位置中即可
// v12 = v_han
// v13 = v12 & 63;//21
// v14 = v13 | 128;//119
// index2 += 1
// v15 = v14 << arr_4[index2 & 3] // 54
// // v16 = arr80某个元素 | v15
// // v16更新到arr80对应位置


function func(_str1) {
    const arr13 = [
        null,
        1732584193,
        4023233417,
        2562383102,
        3285377520,
        false,
        true,
        2147483648,
        4294967295,
        4294967296,
        1518500249,
        1859775393,
        1894007588
    ]; // 固定数组
    let len = _str1.length, count = parseInt(len / 64);
    let arr_4 = [24, 16, 8, 0];
    let flag = 0, code_v;
    let obj5 = {
        "h0": 1732584193,
        "h1": 4023233417,
        "h2": 2562383102,
        "h3": 271733878,
        "h4": 3285377520
    }
    for (let k = 0; k < count; k++) {
        let _newArr80 = [];
        let h0 = obj5.h0, h1 = obj5.h1, h2 = obj5.h2, h3 = obj5.h3, h4 = obj5.h4;
        for (let i = 0; i < 80; i++)
            _newArr80.push(0);
        for (let i = 64 * k, j = 0; i < 64 * k + 64; i++, j++) {
            let index = j >> 2, index2 = j & 3, arr80_v = _newArr80[index], v1, v2;
            if (flag === 0) {
                code_v = _str1.charCodeAt(i);
                if (code_v >= 2048) {
                    v1 = code_v >> 12;
                    v2 = v1 | 224;
                    flag = 1;
                } else {
                    v2 = code_v;
                }
            } else if (flag === 1 || flag === 2) {
                if (flag === 1) {
                    v1 = code_v >> 6;
                    flag = 2;
                } else {
                    v1 = code_v;
                }
                v2 = v1 & 63;
                v2 |= 128;
                if (flag === 2)
                    flag = 0;
            }
            _newArr80[index] = ((v2 << arr_4[index2]) | arr80_v);
        }
        for (let i = 16; i < 80; i++) {
            let v = _newArr80[i - 3] ^ _newArr80[i - 8] ^ _newArr80[i - 14] ^ _newArr80[i - 16];
            v = (v << 1) | (v >>> 31);
            _newArr80[i] = v;
        }
        let arr80 = _newArr80;
        // console.log(arr80);
        for (let i = 0; i < 80; i++) {
            var v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13;
            var v_1, v_2, v_3, v_4, v_5, v_6, v_7, v_8, v_9;
            var flag1 = 0;
            v1 = h0 << 5; // 55
            v2 = h0 >>> 27;//34,
            v3 = v1 | v2;//17
            v4 = h4 + v3;// 34
            v5 = arr80[i];// 17
            v6 = v4 + v5;// 55 8 55

            if (i < 20) {
                v7 = h1 & h2; //17
                v8 = ~h1;// 34
                v9 = v8 & h3;// 11
                v10 = v7 | v9;// 34
                v11 = arr13[10];// 11
                v12 = v10 + v11;// 17
                v13 = v12 + v6;// 55 8
            } else if (i >= 20 && i < 40) {
                v_1 = v6;  //11
                v_2 = h1 ^ h2;//55
                v_3 = v_2 ^ h3; // 17
                v_4 = arr13[11];// 55
                v_5 = v_3 + v_4;// 34
                v_6 = v_1 + v_5;// 11 8
                flag1 = 1;
            } else if (i >= 40 && i < 60) {
                v_1 = v6; // 11
                v_2 = h1 & h2; // 55
                v_3 = h1 & h3; // 34
                v_4 = v_2 | v_3; // 17
                v_5 = h2 & h3;// 34
                v_6 = v_4 | v_5; // 55
                v_7 = arr13[12];// 34
                v_8 = v_6 - v_7; //17
                v_9 = v_8 + v_1; // 11 8
                flag1 = 2;
            } else {
                v_1 = v6; // 34
                v_2 = h1 ^ h2; // 11
                v_3 = h3 ^ v_2; // 17
                v_4 = v_3 - 899497514; // 11
                v_5 = v_1 + v_4; // 34 8
                v_6 = arr13[10]; // 34
                flag1 = 3;
            }

            h4 = h3; // 97 存储 46 的值
            h3 = h2;// 46 存储 131 的值

            var v14, v15, v16;
            v14 = arr13[8];// 34
            v15 = h1 << 30;// 11
            v16 = h1 >>> 2;//17

            h2 = v15 | v16; // 55 131
            h1 = h0;// 15 存储 52 的值
            if (flag1 === 0)
                h0 = v13;// 52
            else if (flag1 === 1)
                h0 = v_6;
            else if (flag1 === 2)
                h0 = v_9;
            else if (flag1 === 3)
                h0 = v_5;
        }
        obj5["h0"] += h0;
        obj5["h1"] += h1;
        obj5["h2"] += h2;
        obj5["h3"] += h3;
        obj5["h4"] += h4;
        for (let k in obj5) {
            obj5[k] <<= 0;
        }
        console.log(obj5);
    }
}


function func2(_str1) {
    const arr13 = [
        null,
        1732584193,
        4023233417,
        2562383102,
        3285377520,
        false,
        true,
        2147483648,
        4294967295,
        4294967296,
        1518500249,
        1859775393,
        1894007588
    ]; // 固定数组
    let len = _str1.length, count = Math.ceil(len / 64);
    let arr_4 = [24, 16, 8, 0];
    let flag = 0, code_v;
    let obj5 = {
        "h0": 1732584193,
        "h1": 4023233417,
        "h2": 2562383102,
        "h3": 271733878,
        "h4": 3285377520
    }
    let j = 0;
    for (let k = 0; k < count; k++) {
        let _newArr80 = [];
        let h0 = obj5.h0, h1 = obj5.h1, h2 = obj5.h2, h3 = obj5.h3, h4 = obj5.h4;
        for (let i = 0; i < 80; i++)
            _newArr80.push(0);
        for (let i = 0; i < 64 && j < len; i++) {
            let index = i >> 2, index2 = j & 3, arr80_v = _newArr80[index], v1, v2;
            if (flag === 0) {
                code_v = _str1.charCodeAt(j);
                if (code_v >= 2048) {
                    v1 = code_v >> 12;
                    v2 = v1 | 224;
                    flag = 1;
                } else {
                    v2 = code_v;
                    j++;
                }
            } else if (flag === 1 || flag === 2) {
                if (flag === 1) {
                    v1 = code_v >> 6;
                    flag = 2;
                } else {
                    v1 = code_v;
                }
                v2 = v1 & 63;
                v2 |= 128;
                if (flag === 2) {
                    flag = 0;
                    j++;
                }
            }
            _newArr80[index] = ((v2 << arr_4[index2]) | arr80_v);
        }
        for (let i = 16; i < 80; i++) {
            let v = _newArr80[i - 3] ^ _newArr80[i - 8] ^ _newArr80[i - 14] ^ _newArr80[i - 16];
            v = (v << 1) | (v >>> 31);
            _newArr80[i] = v;
        }
        let arr80 = _newArr80;
        console.log(k, arr80);
        for (let i = 0; i < 80; i++) {
            var v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13;
            var v_1, v_2, v_3, v_4, v_5, v_6, v_7, v_8, v_9;
            var flag1 = 0;
            v1 = h0 << 5; // 55
            v2 = h0 >>> 27;//34,
            v3 = v1 | v2;//17
            v4 = h4 + v3;// 34
            v5 = arr80[i];// 17
            v6 = v4 + v5;// 55 8 55

            if (i < 20) {
                v7 = h1 & h2; //17
                v8 = ~h1;// 34
                v9 = v8 & h3;// 11
                v10 = v7 | v9;// 34
                v11 = arr13[10];// 11
                v12 = v10 + v11;// 17
                v13 = v12 + v6;// 55 8
            } else if (i >= 20 && i < 40) {
                v_1 = v6;  //11
                v_2 = h1 ^ h2;//55
                v_3 = v_2 ^ h3; // 17
                v_4 = arr13[11];// 55
                v_5 = v_3 + v_4;// 34
                v_6 = v_1 + v_5;// 11 8
                flag1 = 1;
            } else if (i >= 40 && i < 60) {
                v_1 = v6; // 11
                v_2 = h1 & h2; // 55
                v_3 = h1 & h3; // 34
                v_4 = v_2 | v_3; // 17
                v_5 = h2 & h3;// 34
                v_6 = v_4 | v_5; // 55
                v_7 = arr13[12];// 34
                v_8 = v_6 - v_7; //17
                v_9 = v_8 + v_1; // 11 8
                flag1 = 2;
            } else {
                v_1 = v6; // 34
                v_2 = h1 ^ h2; // 11
                v_3 = h3 ^ v_2; // 17
                v_4 = v_3 - 899497514; // 11
                v_5 = v_1 + v_4; // 34 8
                v_6 = arr13[10]; // 34
                flag1 = 3;
            }

            h4 = h3; // 97 存储 46 的值
            h3 = h2;// 46 存储 131 的值

            var v14, v15, v16;
            v14 = arr13[8];// 34
            v15 = h1 << 30;// 11
            v16 = h1 >>> 2;//17

            h2 = v15 | v16; // 55 131
            h1 = h0;// 15 存储 52 的值
            if (flag1 === 0)
                h0 = v13;// 52
            else if (flag1 === 1)
                h0 = v_6;
            else if (flag1 === 2)
                h0 = v_9;
            else if (flag1 === 3)
                h0 = v_5;
        }
        obj5["h0"] += h0;
        obj5["h1"] += h1;
        obj5["h2"] += h2;
        obj5["h3"] += h3;
        obj5["h4"] += h4;
        for (let k in obj5) {
            obj5[k] <<= 0;
        }
        console.log(obj5);
    }
}


function func3(str1) {
    let arr = [];
    let arr_4 = [24, 16, 8, 0], flag = 0;
    let code_v, index, index2, v1, v2,num = 0;
    for (let i = 0; i < str1.length;) {
        if (flag === 0) {
            code_v = str1.charCodeAt(i);
            v2 = code_v;
            index = (i+num) >> 2;
            index2 = (i+num) & 3;
            if (code_v >= 2048) {
                v1 = code_v >> 12;
                v2 = v1 | 224;
                flag = 1;
            } else {
                i++;
            }
        } else if (flag === 1 || flag === 2) {
            if (flag === 1) {
                v1 = code_v >> 6;
                flag = 2;
                num ++;
                index = (i + num) >> 2;
                index2 = (i + num) & 3;
            } else {
                v1 = code_v;
                flag = 0;
                num ++;
                index = (i + num) >> 2;
                index2 = (i + num) & 3;
                i++;
            }
            v2 = v1 & 63;
            v2 |= 128;
        }

        if (arr[index] === undefined) {
            arr[index] = v2 << arr_4[index2];
        } else {
            arr[index] |= (v2 << arr_4[index2]);
        }
        console.log(arr[index],index2,index,i-1,code_v)
    }
    for (let i in arr) {
        console.log(i, arr[i]);
    }
}



const new_arr_4 = [-2147483648, 8388608, 32768, 128];
// 最后一个不满16的数组所进行的操作
// 420 + 6 - 384 = 42
// 42 & 3 = 2 index
// v1 = new_arr_4[index]
// arr80[10] = v2 = v1 | arr80[10] 23

//判断 42 >= 56 false 执行下面操作

// v3 = 426 << 3
// arr80[15] = v3


var obj = {
    "comm": {
        "cv": 4747474,
        "ct": 24,
        "format": "json",
        "inCharset": "utf-8",
        "outCharset": "utf-8",
        "notice": 0,
        "platform": "yqq.json",
        "needNewCode": 1,
        "uin": 3236034970,
        "g_tk_new_20200303": 587132584,
        "g_tk": 587132584
    },
    "req_1": {
        "method": "DoSearchForQQMusicDesktop",
        "module": "music.search.SearchCgiService",
        "param": {
            "remoteplace": "txt.yqq.song",
            "searchid": "70613591748950545",
            "search_type": 0,
            "query": "我的梦",
            "page_num": 1,
            "num_per_page": 10
        }
    }
};
func3(JSON.stringify(obj));







